//
//  ViewController.m
//  ZSTagButton
//
//  Created by safiri on 2018/8/3.
//  Copyright © 2018年 safiri. All rights reserved.
//

#import "ViewController.h"
#import "ZSTagButton.h"
#import "ZSSegmentButtonView.h"
#import "ZSTagButtonView.h"

@interface ViewController ()<ZSSegmentButtonViewDelegate>

@property (nonatomic ,strong) ZSSegmentButtonView *segmentButtonView;

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    ZSButtonTag *tag = [[ZSButtonTag alloc] init];
    tag.text = @"ZSTagButton";
    tag.textColor = [UIColor grayColor];
    tag.fontSize = 22;
    //...
    
    ZSTagButton *button = [ZSTagButton buttonWithTag:tag];
    [button setFrame:CGRectMake(100, 100, 100, 100)];
    [self.view addSubview:button];
    
    //ZSSegmentButtonView.h
    ZSButtonTag *tag1 = [[ZSButtonTag alloc] init];
    tag1.textColor = [self colorWithHexColorString:@"5B6469" alpha:1.0];
    tag1.highlightedTextColor = [self colorWithHexColorString:@"3795F9" alpha:1.0];
    tag1.slcTextColor = [self colorWithHexColorString:@"3795F9" alpha:1.0];
    //    tag.highlightedBgImageColor = [UIColor redColor];
    //    tag.slcBgImageColor = [UIColor redColor];
    if (@available(iOS 8.2, *)) {
        tag1.font = [UIFont systemFontOfSize:15 weight:UIFontWeightMedium];
    } else {
        tag1.font = [UIFont systemFontOfSize:15];
    }
    self.segmentButtonView = [[ZSSegmentButtonView alloc] init];
    self.segmentButtonView.frame = CGRectMake(0, 300, self.view.frame.size.width, 40);
    [self.segmentButtonView createOrRefreshSegViewWithTitleArray:@[@"交易通知",@"系统提醒",@"哈哈",@"三个字"] tag:tag1];
    self.segmentButtonView.lineViewPaddingForLeftRight = self.view.frame.size.width/4*0.2;
    self.segmentButtonView.lineViewHeight = 3;
    self.segmentButtonView.lineViewBackgroundColor = [self colorWithHexColorString:@"3795F9" alpha:1.0];
    self.segmentButtonView.segmentButtonViewDelegate = self;
    [self.view addSubview:self.segmentButtonView];
    
    
    ZSTagButtonView *tagButtonView = [[ZSTagButtonView alloc] initWithFrame:CGRectMake(0, 400, self.view.frame.size.width, 100)];
    tagButtonView.padding = UIEdgeInsetsMake(10, 10, 10, 10);
    tagButtonView.lineSpacing = 10;
    tagButtonView.itemSpacing = 3;
    tagButtonView.didTapTagAtIndex = ^(NSUInteger index) {
        NSLog(@"tagButtonView didTapTagAtIndex: %ld",(long)index);
    };
    tagButtonView.commitLines = ^(NSInteger lines) {
        NSLog(@"tagButtonView commitLines: %ld",(long)lines);
    };
    
    ZSButtonTag *tag2 = [[ZSButtonTag alloc] initWithSameTag:tag1];
    tag2.text = @"ZSButtonTag";
    [tagButtonView addTag:tag2];
    
    ZSButtonTag *tag3 = [[ZSButtonTag alloc] initWithSameTag:tag1];
    tag3.text = @"CGRectMake";
    [tagButtonView insertTag:tag3 atIndex:0];
    
    [tagButtonView addTagTitles:@[@"addSubview",@"hexColorString",@"NSScanner",@"withSameTag",@"segmentButtonSelectTag"] withSameTag:tag1];
    
    [self.view addSubview:tagButtonView];
}
- (void)segmentButtonSelectTag:(NSInteger)tag {
    NSLog(@"tag = %ld",(long)tag);
}
- (UIColor *)colorWithHexColorString:(NSString *)hexColorString alpha:(float)alpha{
    
    unsigned int red, green, blue;
    
    NSRange range;
    
    range.length =2;
    
    range.location =0;
    
    [[NSScanner scannerWithString:[hexColorString substringWithRange:range]]scanHexInt:&red];
    
    range.location =2;
    
    [[NSScanner scannerWithString:[hexColorString substringWithRange:range]]scanHexInt:&green];
    
    range.location =4;
    
    [[NSScanner scannerWithString:[hexColorString substringWithRange:range]]scanHexInt:&blue];
    
    UIColor *color = [UIColor colorWithRed:(float)(red/255.0f)green:(float)(green/255.0f)blue:(float)(blue/255.0f)alpha:alpha];
    
    return color;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
